<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="道路编码" prop="roadId">-->
<!--        <el-input-->
<!--          v-model="queryParams.roadId"-->
<!--          placeholder="请输入道路编码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="道路名称" prop="roadName">-->
<!--        <el-input-->
<!--          v-model="queryParams.roadName"-->
<!--          placeholder="请输入道路名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="隧道编码" prop="tunnelId">-->
<!--        <el-input-->
<!--          v-model="queryParams.tunnelId"-->
<!--          placeholder="请输入隧道编码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="隧道名称" prop="tunnelName">
        <el-input
          v-model="queryParams.tunnelName"
          placeholder="请输入隧道名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="里程桩号" prop="mileageNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.mileageNumber"-->
<!--          placeholder="请输入里程桩号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="设施名称" prop="facilityName">-->
<!--        <el-input-->
<!--          v-model="queryParams.facilityName"-->
<!--          placeholder="请输入设施名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="清洁频率" prop="cleanFrequency">-->
<!--        <el-input-->
<!--          v-model="queryParams.cleanFrequency"-->
<!--          placeholder="请输入清洁频率"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="清洁方案" prop="cleanScheme">-->
<!--        <el-input-->
<!--          v-model="queryParams.cleanScheme"-->
<!--          placeholder="请输入清洁方案"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="上次清洁日期" prop="lastCleanDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.lastCleanDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择上次清洁日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="本次清洁日期" prop="cleanDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.cleanDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择本次清洁日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="养护机构" prop="maintenanceOrganization">-->
<!--        <el-input-->
<!--          v-model="queryParams.maintenanceOrganization"-->
<!--          placeholder="请输入养护机构"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="清洁人员" prop="cleanPerson">
        <el-input
          v-model="queryParams.cleanPerson"
          placeholder="请输入清洁人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="清洁状态" prop="cleanCondition">
        <el-select v-model="queryParams.cleanCondition" placeholder="请输入清洁状态"  clearable >
          <el-option v-for="(item, index) in fieldcleanCondition" :key="index" :label="item.label"
                     :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:cleaning:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['biz:cleaning:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['biz:cleaning:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['biz:cleaning:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cleaningList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="清洁表编号" align="center" prop="tCleanId" />
<!--      <el-table-column label="道路编码" align="center" prop="roadId" />-->
<!--      <el-table-column label="道路名称" align="center" prop="roadName" />-->
<!--      <el-table-column label="隧道编码" align="center" prop="tunnelId" />-->
      <el-table-column label="隧道名称" align="center" prop="tunnelName" />
<!--      <el-table-column label="里程桩号" align="center" prop="mileageNumber" />-->
<!--      <el-table-column label="设施名称" align="center" prop="facilityName" />-->
<!--      <el-table-column label="清洁频率" align="center" prop="cleanFrequency" />-->
<!--      <el-table-column label="清洁方案" align="center" prop="cleanScheme" />-->
<!--      <el-table-column label="上次清洁日期" align="center" prop="lastCleanDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.lastCleanDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="本次清洁日期" align="center" prop="cleanDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.cleanDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="养护机构" align="center" prop="maintenanceOrganization" />
      <el-table-column label="清洁人员" align="center" prop="cleanPerson" />
      <el-table-column label="清洁状态" align="center" prop="cleanCondition" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:cleaning:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:cleaning:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCheck(scope.row)"
            v-hasPermi="['civil:cleaning:edit']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改清洁对话框 -->
    <el-dialog :title="title" :visible.sync="openadd" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!--        公路表：公路名称-->
        <el-form-item label="道路名称"  prop="roadName">
          <el-select v-model="form.roadName" placeholder="请选择道路名称">
            <el-option
              v-for="item in gongluList"
              :key="item.id + ''"
              :label="item.field2"
              :value="item.field2 + ''"
              :disabled="item.status == 1"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--      公路表：根据公路名称确定公路编码-->
        <el-form-item label="道路编码" prop="roadId">
          <el-select v-model="form.roadId" placeholder="请选择道路编码">
            <el-option
              v-for="item in gongluList"
              :key="item.id + ''"
              :label="item.field1"
              :value="item.field1 + ''"
              :disabled="item.status == 1"
              v-if="item.field2 == form.roadName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="隧道编码" prop="tunnelId">
          <el-select v-model="form.tunnelId" placeholder="请选择隧道编码">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.field1 + ''"
              :label="dict.field1"
              :value="dict.field1 + ''"
              v-if="dict.field22 == form.roadName"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--        隧道表：根据隧道编码确定隧道名称-->
        <el-form-item label="隧道名称" prop="tunnelName">
          <el-select v-model="form.tunnelName" placeholder="请选择隧道名称">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.field2 + ''"
              :label="dict.field2"
              :value="dict.field2 + ''"
              v-if="dict.field1 == form.tunnelId"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--        土建结构设备管理表，根据公路、隧道确定里程桩号,，v-if判断多个条件&& 和||-->
        <el-form-item label="里程桩号" prop="mileageNumber">
          <el-select v-model="form.mileageNumber" placeholder="请选择里程桩号">
            <el-option
              v-for="dict in facilityList"
              :key="dict.mileageNumber + ''"
              :label="dict.mileageNumber"
              :value="dict.mileageNumber + ''"
              v-if="dict.roadName == form.roadName && dict.tunnelId == form.tunnelId && dict.tunnelName == form.tunnelName "
            ></el-option>
          </el-select>
        </el-form-item>
        <!--        土建结构设备管理表：根据公路、隧道、里程桩号确定设备-->
        <el-form-item label="设施名称" prop="facilityName">
          <el-select v-model="form.facilityName" placeholder="请选择设施名称">
            <el-option
              v-for="dict in facilityList"
              :key="dict.facilityName + ''"
              :label="dict.facilityName"
              :value="dict.facilityName + ''"
              v-if="dict.roadName == form.roadName &&  dict.tunnelId == form.tunnelId &&  dict.tunnelName == form.tunnelName&&  dict.mileageNumber== form.mileageNumber  "
            ></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="道路编码" prop="roadId">-->
<!--          <el-input v-model="form.roadId" placeholder="请输入道路编码" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="道路名称"  prop="roadName">-->
<!--          <el-select v-model="form.roadName" placeholder="请选择道路">-->
<!--            <el-option-->
<!--              v-for="item in gongluList"-->
<!--              :key="item.id + ''"-->
<!--              :label="item.field2"-->
<!--              :value="item.field2 + ''"-->
<!--              :disabled="item.status == 1"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="隧道编码" prop="tunnelId">-->
<!--          <el-select v-model="form.tunnelId" placeholder="请选择隧道编码">-->
<!--            <el-option-->
<!--              v-for="dict in suidaoList"-->
<!--              :key="dict.field1 + ''"-->
<!--              :label="dict.field1"-->
<!--              :value="dict.field1 + ''"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="隧道名称" prop="tunnelName">-->
<!--          <el-input v-model="form.tunnelName" placeholder="请输入隧道名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="里程桩号" prop="mileageNumber">-->
<!--          <el-input v-model="form.mileageNumber" placeholder="请输入里程桩号" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="设施名称" prop="facilityName">-->
<!--          <el-select v-model="form.facilityName" placeholder="请输入设施名称" clearable :style="{width: '100%'}">-->
<!--            <el-option v-for="(item, index) in fieldfacility" :key="index" :label="item.label"-->
<!--                       :value="item.value" :disabled="item.disabled"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="清洁频率" prop="cleanFrequency">
          <el-input v-model="form.cleanFrequency" placeholder="请输入清洁频率" />
        </el-form-item>
        <el-form-item label="清洁方案" prop="cleanScheme">
          <el-input v-model="form.cleanScheme" placeholder="请输入清洁方案" />
        </el-form-item>
        <el-form-item label="上次日期" prop="lastCleanDate">
          <el-date-picker clearable
            v-model="form.lastCleanDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上次清洁日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="本次日期" prop="cleanDate">
          <el-date-picker clearable
            v-model="form.cleanDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择本次清洁日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="养护机构" prop="maintenanceOrganization">
          <el-input v-model="form.maintenanceOrganization" placeholder="请输入养护机构" />
        </el-form-item>
        <el-form-item label="清洁人员" prop="cleanPerson">
          <el-input v-model="form.cleanPerson" placeholder="请输入清洁人员" />
        </el-form-item>
        <el-form-item label="清洁状态" prop="cleanCondition">
<!--          <el-input v-model="form.cleanCondition" placeholder="请输入清洁状态" />-->
          <el-select v-model="form.cleanCondition" placeholder="请输入清洁状态"  clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in fieldcleanCondition" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 查看清洁对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="道路编码" prop="roadId">
          <el-input v-model="form.roadId" />
        </el-form-item>
        <el-form-item label="道路名称" prop="roadName">
          <el-input v-model="form.roadName" />
        </el-form-item>
        <el-form-item label="隧道编码" prop="tunnelId">
          <el-input v-model="form.tunnelId" />
        </el-form-item>
        <el-form-item label="隧道名称" prop="tunnelName">
          <el-input v-model="form.tunnelName" />
        </el-form-item>
        <el-form-item label="里程桩号" prop="mileageNumber">
          <el-input v-model="form.mileageNumber" />
        </el-form-item>
        <el-form-item label="设施名称" prop="facilityName">
          <el-input v-model="form.facilityName" />
        </el-form-item>
        <el-form-item label="清洁频率" prop="cleanFrequency">
          <el-input v-model="form.cleanFrequency" />
        </el-form-item>
        <el-form-item label="清洁方案" prop="cleanScheme">
          <el-input v-model="form.cleanScheme" />
        </el-form-item>
        <el-form-item label="上次日期" prop="lastCleanDate">
          <el-date-picker clearable
                          v-model="form.lastCleanDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="本次日期" prop="cleanDate">
          <el-date-picker clearable
                          v-model="form.cleanDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="养护机构" prop="maintenanceOrganization">
          <el-input v-model="form.maintenanceOrganization"  />
        </el-form-item>
        <el-form-item label="清洁人员" prop="cleanPerson">
          <el-input v-model="form.cleanPerson" />
        </el-form-item>
        <el-form-item label="清洁状态" prop="cleanCondition">
          <el-input v-model="form.cleanCondition" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCleaning, getCleaning, delCleaning, addCleaning, updateCleaning,exportCleaning,} from "@/api/biz/cleaning";
import { exportAllmaintenance, getAllmaintenance } from '@/api/biz/allmaintenance'
import { listSuidao } from "@/api/biz/suidao";
import { listGonglu } from "@/api/biz/gonglu";
import { listFacility } from '@/api/civil/facility'

export default {
  name: "Cleaning",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 清洁表格数据
      cleaningList: [],
      //隧道列表
      suidaoList: [],
      //道路列表
      gongluList: [],
      //设备列表
      facilityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示增加或修改的弹出层
      openadd: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roadId: null,
        roadName: null,
        tunnelId: null,
        tunnelName: null,
        mileageNumber: null,
        facilityName: null,
        cleanFrequency: null,
        cleanScheme: null,
        lastCleanDate: null,
        cleanDate: null,
        maintenanceOrganization: null,
        cleanPerson: null,
        cleanCondition: null
      },
      // 表单参数
      form: {},
      fieldcleanCondition: [{
        "label": "未清洁",
        "value": "未清洁"
      }, {
        "label": "清洁中",
        "value": "清洁中"
      },{
        "label": "已清洁",
        "value": "已清洁"
      },
      ],
      fieldfacility: [{
        "label": "洞口",
        "value": "洞口"
      }, {
        "label": "洞门",
        "value": "洞门"
      },{
        "label": "衬砌",
        "value": "衬砌"
      },{
        "label": "路面",
        "value": "路面"
      },{
        "label": "检修道",
        "value": "检修道"
      },{
        "label": "排水设施",
        "value": "排水设施"
      },{
        "label": "吊顶及预埋件",
        "value": "吊顶及预埋件"
      },{
        "label": "装饰物",
        "value": "装饰物"
      }, {
        "label": "交通标志/标线",
        "value": "交通标志/标线"
      }
      ],

      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    listSuidao({}).then((response) => {
      this.suidaoList = response.rows;
    });
    listGonglu({}).then((response) => {
      this.gongluList = response.rows;
    });
    listFacility({}).then((response) => {
      this.facilityList = response.rows;
    });
  },
  methods: {
    /** 查询清洁列表 */
    getList() {
      this.loading = true;
      listCleaning(this.queryParams).then(response => {
        this.cleaningList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.openadd = false;
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        tCleanId: null,
        roadId: null,
        roadName: null,
        tunnelId: null,
        tunnelName: null,
        mileageNumber: null,
        facilityName: null,
        cleanFrequency: null,
        cleanScheme: null,
        lastCleanDate: null,
        cleanDate: null,
        maintenanceOrganization: null,
        cleanPerson: null,
        cleanCondition: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.tCleanId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openadd = true;
      this.title = "添加清洁";
      this.form.roadId = this.$route.query.roadid
      this.form.roadName = this.$route.query.roadname
      this.form.tunnelId = this.$route.query.tunnelid
      this.form.tunnelName = this.$route.query.tunnelname
      this.form.maintenanceOrganization = this.$route.query.maintenanceorganization
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const tCleanId = row.tCleanId || this.ids
      getCleaning(tCleanId).then(response => {
        this.form = response.data;
        this.openadd = true;
        this.title = "修改清洁";
      });
    },
    /** 查看按钮操作 */
    handleCheck(row) {
      this.reset();
      const tCleanId = row.tCleanId || this.ids
      getCleaning(tCleanId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看清洁";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.tCleanId != null) {
            updateCleaning(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openadd = false;
              this.getList();
            });
          } else {
            addCleaning(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openadd = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const tCleanIds = row.tCleanId || this.ids;
      this.$modal.confirm('是否确认删除清洁编号为"' + tCleanIds + '"的数据项？').then(function() {
        return delCleaning(tCleanIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  //   /** 导出按钮操作 */
  //   handleExport() {
  //     this.download('biz/cleaning/export', {
  //       ...this.queryParams
  //     }, `cleaning_${new Date().getTime()}.xlsx`)
  //   }
  // }
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportCleaning(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
